<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是LCD应用编程——FreeType库的应用的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV18-01-LCD应用编程-08-FreeType库的应用">
<meta property="og:url" content="https://sumumm.github.io/post/449e2fe8.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是LCD应用编程——FreeType库的应用的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017070141165.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241016072025141.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241016072949057.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/QQ_1729120147270.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/QQ_1729120479524.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017072320624.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017225852013.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017230645057.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017230749109.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017232439951.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018065536878.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/dadf112c33564ecfa089414f560799a8.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018070755124.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018071235509.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018074744359.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018080116270.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018222432829.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018222628602.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018233207290.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018233242368.png">
<meta property="article:published_time" content="2024-10-27T11:29:54.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.036Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="(ALPHA)LV03-应用开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017070141165.png">


<link rel="canonical" href="https://sumumm.github.io/post/449e2fe8.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":"","permalink":"https://sumumm.github.io/post/449e2fe8.html","path":"post/449e2fe8.html","title":"LV18-01-LCD应用编程-08-FreeType库的应用"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV18-01-LCD应用编程-08-FreeType库的应用 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="nav-text">一、基本概念</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%AD%97%E5%BD%A2%EF%BC%88glyph%EF%BC%89"><span class="nav-text">1. 字形（glyph）  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E5%83%8F%E7%B4%A0%E7%82%B9%EF%BC%88pixel%EF%BC%89%E3%80%81%E7%82%B9%EF%BC%88point%EF%BC%89%E4%BB%A5%E5%8F%8A-dpi"><span class="nav-text">2. 像素点（pixel）、点（point）以及 dpi  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%AD%97%E5%BD%A2%E7%9A%84%E5%B8%83%E5%B1%80"><span class="nav-text">3. 字形的布局  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%AD%97%E4%BD%93%E6%96%87%E4%BB%B6%E4%B8%8E%E5%AD%97%E5%BD%A2%E7%B4%A2%E5%BC%95"><span class="nav-text">4. 字体文件与字形索引</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E6%98%BE%E7%A4%BA%E4%B8%80%E4%B8%AA%E5%AD%97%E7%AC%A6"><span class="nav-text">二、显示一个字符</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-Freetype%E6%98%BE%E7%A4%BA%E5%AD%97%E7%AC%A6%E5%9F%BA%E6%9C%AC%E6%B5%81%E7%A8%8B"><span class="nav-text">1. Freetype显示字符基本流程</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%98%BE%E7%A4%BA%E4%B8%80%E4%B8%AA%E7%9F%A2%E9%87%8F%E5%AD%97%E4%BD%93"><span class="nav-text">2. 显示一个矢量字体</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E4%BD%BF%E7%94%A8-wchar-t-%E8%8E%B7%E5%BE%97%E5%AD%97%E7%AC%A6%E7%9A%84-UNICODE-%E5%80%BC"><span class="nav-text">2.1 使用 wchar_t 获得字符的 UNICODE 值  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%BD%BF%E7%94%A8-freetype-%E5%BE%97%E5%88%B0%E4%BD%8D%E5%9B%BE"><span class="nav-text">2.2 使用 freetype 得到位图  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E5%9C%A8%E5%B1%8F%E5%B9%95%E4%B8%8A%E6%98%BE%E7%A4%BA%E4%BD%8D%E5%9B%BE"><span class="nav-text">2.3 在屏幕上显示位图  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E5%AE%8C%E6%95%B4%E5%AE%9E%E4%BE%8B"><span class="nav-text">2.4 完整实例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E4%BB%A4%E7%9F%A2%E9%87%8F%E5%AD%97%E4%BD%93%E6%97%8B%E8%BD%AC%E6%9F%90%E4%B8%AA%E8%A7%92%E5%BA%A6"><span class="nav-text">3. 令矢量字体旋转某个角度  </span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E6%98%BE%E7%A4%BA%E4%B8%80%E8%A1%8C%E5%AD%97%E7%AC%A6"><span class="nav-text">三、显示一行字符</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E7%AC%9B%E5%8D%A1%E5%B0%94%E5%9D%90%E6%A0%87%E7%B3%BB"><span class="nav-text">1. 笛卡尔坐标系</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E6%AF%8F%E4%B8%AA%E5%AD%97%E7%AC%A6%E5%A4%A7%E5%B0%8F%E4%B8%8D%E5%90%8C%EF%BC%9F"><span class="nav-text">2. 每个字符大小不同？</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E6%98%BE%E7%A4%BA%E4%B8%80%E8%A1%8C%E5%AD%97%E7%AC%A6"><span class="nav-text">3. 显示一行字符</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-freetype-%E7%9A%84%E5%87%A0%E4%B8%AA%E9%87%8D%E8%A6%81%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84"><span class="nav-text">4. freetype 的几个重要数据结构  </span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-FT-Library"><span class="nav-text">4.1 FT_Library  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-FT-Face"><span class="nav-text">4.2 FT_Face  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-FT-GlyphSlot"><span class="nav-text">4.3 FT_GlyphSlot  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-4-FT-Glyph"><span class="nav-text">4.4 FT_Glyph  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-5-FT-BBox"><span class="nav-text">4.5 FT_BBox  </span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E8%AE%BE%E7%BD%AE%E5%AD%97%E4%BD%93%E5%A4%A7%E5%B0%8F"><span class="nav-text">5. 设置字体大小</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#5-1-FT-Set-Pixel-Sizes-%E5%87%BD%E6%95%B0"><span class="nav-text">5.1 FT_Set_Pixel_Sizes()函数  </span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-2-FT-Set-Char-Size-%E5%87%BD%E6%95%B0"><span class="nav-text">5.2 FT_Set_Char_Size()函数  </span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E5%AE%9E%E4%BE%8B%E4%BB%A3%E7%A0%81%E6%A1%86%E6%9E%B6"><span class="nav-text">6. 实例代码框架</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E5%AE%8C%E6%95%B4%E5%AE%9E%E4%BE%8B"><span class="nav-text">7. 完整实例</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1-%E5%AE%9E%E4%BE%8B1"><span class="nav-text">7.1 实例1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-2-%E5%AE%9E%E4%BE%8B2"><span class="nav-text">7.2 实例2</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/449e2fe8.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV18-01-LCD应用编程-08-FreeType库的应用 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV18-01-LCD应用编程-08-FreeType库的应用
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-10-27 19:29:54" itemprop="dateCreated datePublished" datetime="2024-10-27T19:29:54+08:00">2024-10-27</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/" itemprop="url" rel="index"><span itemprop="name">02IMX6ULL平台</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV03-应用开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>8.3k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>30 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是LCD应用编程——FreeType库的应用的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" rowspan="5">PC端开发环境</td>        <td align="center" width=150px>Windows</td>        <td align="left">Windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu20.04.2的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 17 Pro</td>        <td align="left">17.6.0 build-24238078</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>    </tr>    <tr>        <td align="center">Win32DiskImager</td>        <td align="left">Win32DiskImager v1.0</td>      </tr>    <tr>        <td align="center" rowspan="3">Linux开发板环境</td>        <td align="center">Linux开发板</td>        <td align="left">正点原子 i.MX6ULL Linux 阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="5">官方网站</td>        <td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td>        <td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/" target="_blank">https://www.nxp.com.cn/ </a></td>        <td align="left">NXP官方网站</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxpic.org.cn/" target="_blank">https://www.nxpic.org.cn/</a></td><td align="left">NXP 官方社区</td>    </tr>    <tr>        <td align="left"><a href="https://u-boot.readthedocs.io/en/latest/" target="_blank">https://u-boot.readthedocs.io/en/latest/</a></td><td align="left">u-boot官网</td>    </tr>    <tr>        <td align="left"><a href="https://www.kernel.org/" target="_blank">https://www.kernel.org/</a></td><td align="left">linux内核官网</td>    </tr>    <tr>        <td align="center" rowspan="5">其他网站</td>        <td align="left"><a href="https://elixir.bootlin.com/linux/v4.15/source/kernel" target="_blank">kernel - Linux source code (v4.15) - Bootlin</a></td>        <td align="left">linux内核源码在线查看</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="4">NXP</td>        <td align="left"><a href="https://github.com/nxp-imx" target="_blank">https://github.com/nxp-imx</a></td>        <td align="left">NXP imx开发资源GitHub组织，里边会有u-boot和linux内核的仓库</td>    </tr>    <tr>        <td align="left"><a href="https://elixir.bootlin.com/linux/latest/source" target="_blank">https://elixir.bootlin.com/linux/latest/source</a></td>        <td align="left">在线阅读linux kernel源码</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP linux内核仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP u-boot仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="center" rowspan="2">I.MX6ULL</td>        <td align="left"><a href="https://www.nxp.com.cn/docs/en/data-sheet/IMX6ULLIEC.pdf" target="_blank">i.MX 6ULL Applications Processors for Industrial Products</a></td>        <td align="left">I.MX6ULL 芯片手册（datasheet，可以在线查看）</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/webapp/Download?colCode=IMX6ULLRM&lang_cd=zh" target="_blank">i.MX 6ULL Applications ProcessorReference Manual</a></td>        <td align="left">I.MX6ULL 参考手册（下载后才能查看，需要登录NXP官网）</td>    </tr></table>
              </div>
            </details>

<h1 id="一、基本概念"><a href="#一、基本概念" class="headerlink" title="一、基本概念"></a><font size=3>一、基本概念</font></h1><h2 id="1-字形（glyph）"><a href="#1-字形（glyph）" class="headerlink" title="1. 字形（glyph）  "></a><font size=3>1. 字形（glyph）  </font></h2><p>字符图像就叫做字形，也可以叫关键点，一个字符能够有多种不同的字形，可以理解为字形就是字符的一种书写风格，如宋体的汉字“国”与微软雅黑的汉字“国”，它们的字形是不同的，也就是它们书写风格是不同；宋体的“国”与微软雅黑的“国”就是两种不同的字形。 </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017070141165.png" alt="image-20241017070141165" />

<p>我们找到这些关键点，然后用数学曲线(比如贝塞尔曲线)将关键点都连接起来， 得到一系列的封闭的曲线，最后把封闭空间填满颜色，就显示出一个 A 字母如果需要放大或者缩小字体， 关键点的相对位置是不变的， 只要数学曲线平滑，字体就不会变形，通过关键点得来的这些字体就是矢量字体，即便放大或者缩小也不会有太明显的锯齿。      </p>
<h2 id="2-像素点（pixel）、点（point）以及-dpi"><a href="#2-像素点（pixel）、点（point）以及-dpi" class="headerlink" title="2. 像素点（pixel）、点（point）以及 dpi  "></a><font size=3>2. 像素点（pixel）、点（point）以及 dpi  </font></h2><p>像素点我们都知道，如 LCD 分辨率为 800*480，那就表示 LCD 水平方向有 800 个像素点、垂直方向有 480 个像素点，所以此 LCD 一共有 800*480 个像素点。</p>
<p>接下来看一下“点”的概念， 点（point）是一种简单的物理单位，在数字印刷中，一个点（point）等于 1&#x2F;72 英寸（1 英寸等于 25.4 毫米）。除此之外，还有一个 dpi 的概念， dpi（dots per inch）表示每英寸的像素点数，如 300*400dpi 表示在水平方向，每英寸有 300 个像素点、在垂直方向上每英寸有 400 个像素点。 通过点数和 dpi 可以计算出像素点数，公式如下：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">像素点数 = 点数 * dpi / 72</span><br></pre></td></tr></table></figure>

<p>如，假设某一显示设备水平方向 dpi 为 300，已知水平方向的点数为 50，那么像素点数的计算方式为：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">50 * 300 / 72 = 208</span><br></pre></td></tr></table></figure>

<p>所以可以算出像素点数为 208。  </p>
<h2 id="3-字形的布局"><a href="#3-字形的布局" class="headerlink" title="3. 字形的布局  "></a><font size=3>3. 字形的布局  </font></h2><p>以下两张图清晰地描述了字形布局的情况：分为水平布局和垂直布局， 以下这两张图都是从官方的文档中截取过来的。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241016072025141.png" alt="image-20241016072025141" />

<p align="center">图一-4.1 字形的布局</p>

<p>水平方向书写文字使用水平布局方式，绝大部分情况下我们一般都是在水平方向上书写文字；垂直方向书写文字使用垂直布局方式，对于汉字来说，垂直方向书写也是比较常见的，很有代表性的就是对联、还有很多古书文字的写法， 也都是采用这种垂直书写。  </p>
<ul>
<li>基准线、原点</li>
</ul>
<p>从图中可以看到，不管是水平布局还是垂直布局，图中都可以找到一个 origin 原点， 经过原点的水平线（X 轴）和垂直线（Y 轴）称为基准线，为方便描述，可以将其称为水平基线和垂直基线。</p>
<p>对于水平布局， 垂直基线在字形的左边，垂直基线简单地放置在字形上，通过图中所标注的度量数据确定与基线的位置关系。</p>
<p>对于垂直布局，水平基线在字形的上方，字形在垂直基线上居中放置，同样也是通过图中所标注的度量数据确定与基线的位置关系。原点、基准线可以用于定位字形，水平布局和垂直布局使用不同的约束来放置字形。  </p>
<ul>
<li>字形的宽度和高度</li>
</ul>
<p>每一个字形都有自己的宽度和高度，图中使用 width（宽）和 height（高）来表示， width 描述了字形轮廓的最左边到最右边的距离；而height 描述了字形轮廓的最上边到最下边的距离。同一种书写风格，不同字符所对应的字形，它们的宽高是不一定相等的，如大写 A 和小写 a，宽度和高度明显是不同的；但有些字符的字形宽度和高度是相同的，这个与具体的字符有关。</p>
<ul>
<li>bearingX 和 bearingY</li>
</ul>
<p>bearingX 表示从垂直基线到字形轮廓最左边的距离。对于水平布局来说， 字形在垂直基线的右侧，所以bearingX 是一个正数；而对于垂直布局来说， 字形在垂直基线上居中放置，所以字形轮廓的最左边通常是在垂直基线的左侧，所以 bearingX 是一个负数。</p>
<p>bearingY 则表示从水平基线到字形轮廓最上边的距离。 对于垂直布局来说， bearingY 是一个正数，字形处于水平基线的下方；而对于水平布局来说， 如果字形轮廓的最上边在水平基线的上方，则 bearingY 是一个正数、相反则是一个负数。  </p>
<ul>
<li>xMin&#x2F;xMax、 yMin&#x2F;yMax</li>
</ul>
<p>xMin 表示字形轮廓最左边的位置， xMax 则表示字形轮廓最右边的位置； yMin 表示字形轮廓最下边的位置， yMax 则表示字形轮廓最上边的位置，通过这 4 个位置可以构成一个字形的边界框（bounding box，bbox），当然这是一个假象的框子，它尽可能紧密的装入字形。  </p>
<ul>
<li>advance</li>
</ul>
<p>advance 则表示步进宽度， 相邻两个原点位置的距离(字间距)。如果是水平布局，则表示相邻的两个原点在水平方向上的距离（advanceX） ，也就是相邻两条垂直基线之间的距离；</p>
<p>同理，如果是垂直布局，则表示相邻的两个原点在垂直方向上的距离（advanceY） ，也就是相邻两条水平基线之间的距离。  </p>
<h2 id="4-字体文件与字形索引"><a href="#4-字体文件与字形索引" class="headerlink" title="4. 字体文件与字形索引"></a><font size=3>4. 字体文件与字形索引</font></h2><p>前面我们知道我们只需要移植这个freetype字体引擎，调用对应的 API 接口，提供字体文件，就可以让 freetype 库帮我们取出字形(glyph) 、实现闭合曲线， 填充颜色， 达到显示矢量字体的目的。</p>
<p>字形存在字体文件中，Windows使用的字体文件在c:\Windows\Fonts 目录下，扩展名为 TTF 的都是矢量字库，   </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241016072949057.png" alt="image-20241016072949057" />

<p>使用 FreeType 访问字体文件， 可以从字体文件中获取到字形的位图数据，位图数据存储在一个 buffer中， buffer 大小为字形的宽*高个字节（字形边界框的宽*高个字节） ，也就是 图一-4.1 字形的布局 中 width*height 个字节大小， 每一个点使用一个字节来表示，当数组中该点对应的数值等于 0，表示该点不填充颜色；当数值大于 0，表示该点需要填充颜色。  </p>
<p>在字体文件中，通过字形索引找到对应的字形， 而字形索引是由字符编码转换而来的， 如 ASCII 编码、 GB2312 编码、 BIG5 编码、 GBK 编码以及国际标准字符集使用的 Unicode 编码等。 对于字符编码，可以看这个《01嵌入式开发&#x2F;01HQ课程体系&#x2F;LV16-STM32开发&#x2F;LV16-26-LCD-05-字符编码.md》和《01嵌入式开发&#x2F;02IMX6ULL平台&#x2F;LV03-应用开发&#x2F;LV18-01-LCD应用编程-08-FreeType库的应用.md》。  怎么快速预览某个字体的编码值？</p>
<p>控制面板&rarr;查看方式改为大图标（打开所有控制面板项）&rarr;字体：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/QQ_1729120147270.png" alt="QQ_1729120147270" style="zoom: 33%;" />

<p>打开字体面板之后，点击左边菜单栏的查找字符，这里就能看到啦：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/QQ_1729120479524.png" alt="QQ_1729120479524" style="zoom:33%;" />

<p>怎么在字体文件中找到它的字形？首先要确定该字符的编码值：比如 ASCII 码、 GB2312 码、 UNICODE 码。如果字体文件支持某种编码格式(charset)，就可以使用这类编码值去找到该字符的字形(glyph)。有些字体文件支持多种编码格式(charset)，这在文件中被称为charmaps (注意：这个单词是复数，意味着可能支持多种 charset)。   </p>
<p>以 simsun.ttc （常规宋体）为例，该字体文件的格如下：头部含有 charmaps，可以使用某种编码值去 charmaps 中找到它对应的关键点。下图中的“ A、 B、中、国”等只是 glyph 的示意图，表示字形。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017072320624.png" alt="image-20241017072320624" />

<p>Charmaps 表示字符映射表， 字体文件可能支持哪一些编码， GB2312、UNICODE、 BIG5 或其他。如果字体文件支持该编码， 使用编码值通过 charmap 就可以找到对应的 glyph， 一般而言都支持 UNICODE 码。 </p>
<h1 id="二、显示一个字符"><a href="#二、显示一个字符" class="headerlink" title="二、显示一个字符"></a><font size=3>二、显示一个字符</font></h1><h2 id="1-Freetype显示字符基本流程"><a href="#1-Freetype显示字符基本流程" class="headerlink" title="1. Freetype显示字符基本流程"></a><font size=3>1. Freetype显示字符基本流程</font></h2><p>一个文字的显示过程可以概括如下：  </p>
<p>（1）给定一个字符可以确定它的编码值(ASCII、 UNICODE、 GB2312)；</p>
<p>（2）设置字体大小；</p>
<p>（3）根据编码值，从文件头部中通过 charmap 找到对应的关键点(glyph)，它会根据字体大小调整字形；</p>
<p>（4）把字形转换为位图点阵；</p>
<p>（5）在 LCD 上显示出来。</p>
<p>我们根据freetype官方库的说明文档可以总结出下列步骤：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// (1)初始化： FT_InitFreetype</span></span><br><span class="line">FT_Init_FreeType( FT_Library *alibrary );</span><br><span class="line"><span class="comment">// (2)加载(打开)字体 Face： FT_New_Face</span></span><br><span class="line">FT_New_Face( FT_Library library, <span class="type">const</span> <span class="type">char</span>* filepathname, FT_Long face_index, FT_Face *aface );</span><br><span class="line"><span class="comment">// (3)设置字体大小： FT_Set_Char_Sizes 或 FT_Set_Pixel_Sizes</span></span><br><span class="line">FT_Set_Pixel_Sizes( FT_Face face, FT_UInt  pixel_width, FT_UInt pixel_height );</span><br><span class="line"></span><br><span class="line"><span class="comment">// (4)选择 charmap： FT_Select_Charmap</span></span><br><span class="line">FT_Select_Charmap( FT_Face face, FT_Encoding  encoding );</span><br><span class="line"><span class="comment">// (5)根据编码值 charcode 找到 glyph_index： glyph_index = FT_Get_Char_Index(face， charcode)</span></span><br><span class="line">FT_Get_Char_Index( FT_Face   face, FT_ULong  charcode );</span><br><span class="line"><span class="comment">// (6)根据 glyph_index 取出 glyph： FT_Load_Glyph(face， glyph_index)</span></span><br><span class="line">FT_Load_Glyph( FT_Face   face, FT_UInt   glyph_index, FT_Int32  load_flags );</span><br><span class="line"><span class="comment">// (7)转为位图： FT_Render_Glyph</span></span><br><span class="line">FT_Render_Glyph( FT_GlyphSlot slot, FT_Render_Mode  render_mode );</span><br><span class="line"><span class="comment">// (8)移动或旋转:FT_Set_Transform</span></span><br><span class="line">FT_Set_Transform( FT_Face face, FT_Matrix*  matrix, FT_Vector*  delta );</span><br><span class="line"><span class="comment">// (9)最后显示出来。</span></span><br><span class="line">LCD_show</span><br></pre></td></tr></table></figure>

<p>上面的（5）（6）（7）可以使用一个函数代替： FT_Load_Char(face, charcode, FT_LOAD_RENDER)，它就可以得到位图。  </p>
<h2 id="2-显示一个矢量字体"><a href="#2-显示一个矢量字体" class="headerlink" title="2. 显示一个矢量字体"></a><font size=3>2. 显示一个矢量字体</font></h2><h3 id="2-1-使用-wchar-t-获得字符的-UNICODE-值"><a href="#2-1-使用-wchar-t-获得字符的-UNICODE-值" class="headerlink" title="2.1 使用 wchar_t 获得字符的 UNICODE 值  "></a><font size=3>2.1 使用 wchar_t 获得字符的 UNICODE 值  </font></h3><p>要显示一个字符，首先要确定它的编码值。 上一节学习字符编码的时候有学习过这个类型：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;wchar.h&gt;</span></span></span><br><span class="line"><span class="type">wchar_t</span> *chinese_str = <span class="string">L&quot;中 gif&quot;</span>;</span><br></pre></td></tr></table></figure>

<h3 id="2-2-使用-freetype-得到位图"><a href="#2-2-使用-freetype-得到位图" class="headerlink" title="2.2 使用 freetype 得到位图  "></a><font size=3>2.2 使用 freetype 得到位图  </font></h3><p>要使用 freetype 得到一个字符的位图，只需要 4 个步骤 ：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 显示矢量字体 */</span></span><br><span class="line">error = FT_Init_FreeType( &amp;library );			   <span class="comment">/* initialize library */</span></span><br><span class="line"><span class="comment">/* error handling omitted */</span></span><br><span class="line"></span><br><span class="line">error = FT_New_Face( library, argv[<span class="number">1</span>], <span class="number">0</span>, &amp;face ); <span class="comment">/* create face object */</span></span><br><span class="line"><span class="comment">/* error handling omitted */</span>	</span><br><span class="line">slot = face-&gt;glyph;</span><br><span class="line"></span><br><span class="line">FT_Set_Pixel_Sizes(face, font_size, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* 确定坐标:</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">//pen.x = 0;</span></span><br><span class="line"><span class="comment">//pen.y = 0;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* set transformation */</span></span><br><span class="line"><span class="comment">//FT_Set_Transform( face, 0, &amp;pen);</span></span><br><span class="line"></span><br><span class="line"><span class="comment">/* load glyph image into the slot (erase previous one) */</span></span><br><span class="line">error = FT_Load_Char( face, chinese_str[<span class="number">0</span>], FT_LOAD_RENDER );</span><br><span class="line"><span class="keyword">if</span> (error)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;FT_Load_Char error\n&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>1、初始化 freetype 库</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">error = FT_Init_FreeType( &amp;library );			   <span class="comment">/* initialize library */</span></span><br></pre></td></tr></table></figure>

<ul>
<li>2、加载字体文件， 保存在&amp;face 中：</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">error = FT_New_Face( library, argv[<span class="number">1</span>], <span class="number">0</span>, &amp;face ); <span class="comment">/* create face object */</span></span><br><span class="line"><span class="comment">/* error handling omitted */</span>	</span><br><span class="line">slot = face-&gt;glyph;</span><br></pre></td></tr></table></figure>

<p>这里的第3行是从 face 中获得 FT_GlyphSlot，后面的代码中文字的位图就是保存在 FT_GlyphSlot 里。  </p>
<ul>
<li>3、设置字体大小</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FT_Set_Pixel_Sizes(face, font_size, <span class="number">0</span>);</span><br></pre></td></tr></table></figure>

<ul>
<li>4、根据编码值得到位图。使用 FT_Load_Char 函数，就可以实现这 3 个功能：</li>
</ul>
<p>（1）根据编码值获得 glyph_index： FT_Get_Char_Index</p>
<p>（2）根据 glyph_idex 取出 glyph： FT_Load_Glyph</p>
<p>（3）渲染出位图： FT_Render_Glyph  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">error = FT_Load_Char( face, chinese_str[<span class="number">0</span>], FT_LOAD_RENDER );</span><br></pre></td></tr></table></figure>

<p>执行 FT_Load_Char 之后，字符的位图被存在 slot&rarr;bitmap 里 ， 即face&rarr;glyph&rarr;bitmap。  </p>
<h3 id="2-3-在屏幕上显示位图"><a href="#2-3-在屏幕上显示位图" class="headerlink" title="2.3 在屏幕上显示位图  "></a><font size=3>2.3 在屏幕上显示位图  </font></h3><p>位图里的数据格式是怎样的？参考 example1.c 的代码，可以得到下图：  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017225852013.png" alt="image-20241017225852013" />

<p>要在屏幕上显示出这些位图，就是把位图对应的像素点用对应的颜色填充。draw_bitmap 函数代码如下，由于位图中每一个像素用一个字节来表示，在0x00RRGGBB 的颜色格式中它只能表示蓝色，所以在 LCD上显示出来的文字是蓝色的： </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">void</span> <span class="title function_">draw_bitmap</span><span class="params">( FT_Bitmap* bitmap, FT_Int x, FT_Int y)</span></span><br><span class="line">&#123;</span><br><span class="line">	FT_Int  i, j, p, q;</span><br><span class="line">	FT_Int  x_max = x + bitmap-&gt;width;</span><br><span class="line">	FT_Int  y_max = y + bitmap-&gt;rows;</span><br><span class="line"></span><br><span class="line">	<span class="comment">//printf(&quot;x = %d, y = %d\n&quot;, x, y);</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">for</span> ( j = y, q = <span class="number">0</span>; j &lt; y_max; j++, q++ )</span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">for</span> ( i = x, p = <span class="number">0</span>; i &lt; x_max; i++, p++ )</span><br><span class="line">		&#123;</span><br><span class="line">			<span class="keyword">if</span> ( i &lt; <span class="number">0</span>      || j &lt; <span class="number">0</span>       ||</span><br><span class="line">				i &gt;= var.xres || j &gt;= var.yres )</span><br><span class="line">			<span class="keyword">continue</span>;</span><br><span class="line"></span><br><span class="line">			<span class="comment">//image[j][i] |= bitmap-&gt;buffer[q * bitmap-&gt;width + p];</span></span><br><span class="line">			lcd_put_pixel(i, j, bitmap-&gt;buffer[q * bitmap-&gt;width + p]);</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="2-4-完整实例"><a href="#2-4-完整实例" class="headerlink" title="2.4 完整实例"></a><font size=3>2.4 完整实例</font></h3><p>完整的代码和Makefile看这里吧：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-app-demo/tree/master/LV18_LCD_DEVICE/07_lcd_freetype_show_font">LV18_LCD_DEVICE&#x2F;07_lcd_freetype_show_font · 苏木&#x2F;imx6ull-app-demo - 码云 - 开源中国 (gitee.com)</a></p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017230645057.png" alt="image-20241017230645057" />

<p>我们编译后通过以下命令执行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./app_demo ./data/simfang.ttf</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017230749109.png" alt="image-20241017230749109" />

<h2 id="3-令矢量字体旋转某个角度"><a href="#3-令矢量字体旋转某个角度" class="headerlink" title="3. 令矢量字体旋转某个角度  "></a><font size=3>3. 令矢量字体旋转某个角度  </font></h2><p>在实现显示一个矢量字体后，我们可以添加让该字旋转某个角度的功能， 主要代码还是参照官网的这个例子：</p>
<p><a target="_blank" rel="noopener" href="https://freetype.org/freetype2/docs/tutorial/example1.c">freetype.org&#x2F;freetype2&#x2F;docs&#x2F;tutorial&#x2F;example1.c</a>。  </p>
<ul>
<li>1、定义 2 个变量：角度、矩阵</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">FT_Matrix	  matrix;				  <span class="comment">/* transformation matrix */</span></span><br><span class="line"><span class="type">double</span>		  angle;</span><br></pre></td></tr></table></figure>

<ul>
<li>2、设置角度值</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">angle  = ( <span class="number">1.0</span>* strtoul(argv[<span class="number">2</span>], <span class="literal">NULL</span>, <span class="number">0</span>) / <span class="number">360</span> ) * <span class="number">3.14159</span> * <span class="number">2</span>;	   <span class="comment">/* use 25 degrees	 */</span></span><br></pre></td></tr></table></figure>

<ul>
<li>3、设置矩阵、 变形、加载位图</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 确定坐标:</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line">pen.x = <span class="number">0</span>;</span><br><span class="line">pen.y = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">/* set up matrix */</span></span><br><span class="line">matrix.xx = (FT_Fixed)( <span class="built_in">cos</span>( angle ) * <span class="number">0x10000</span>L );</span><br><span class="line">matrix.xy = (FT_Fixed)(-<span class="built_in">sin</span>( angle ) * <span class="number">0x10000</span>L );</span><br><span class="line">matrix.yx = (FT_Fixed)( <span class="built_in">sin</span>( angle ) * <span class="number">0x10000</span>L );</span><br><span class="line">matrix.yy = (FT_Fixed)( <span class="built_in">cos</span>( angle ) * <span class="number">0x10000</span>L );</span><br><span class="line"></span><br><span class="line"><span class="comment">/* set transformation */</span></span><br><span class="line">FT_Set_Transform( face, &amp;matrix, &amp;pen);</span><br><span class="line"></span><br><span class="line"><span class="comment">/* load glyph image into the slot (erase previous one) */</span></span><br><span class="line">error = FT_Load_Char( face, chinese_str[<span class="number">0</span>], FT_LOAD_RENDER );</span><br><span class="line"><span class="keyword">if</span> (error)</span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;FT_Load_Char error\n&quot;</span>);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>完整实例和Makefile可以看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-app-demo/tree/master/LV18_LCD_DEVICE/08_lcd_freetype_show_font_angle">LV18_LCD_DEVICE&#x2F;08_lcd_freetype_show_font_angle · 苏木&#x2F;imx6ull-app-demo - 码云 - 开源中国 (gitee.com)</a>，编译完毕，可以通过以下命令执行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./app_demo ./data/simfang.ttf 30 200</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241017232439951.png" alt="image-20241017232439951" />

<h1 id="三、显示一行字符"><a href="#三、显示一行字符" class="headerlink" title="三、显示一行字符"></a><font size=3>三、显示一行字符</font></h1><p>如何显示一行文字？如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018065536878.png" alt="image-20241018065536878" style="zoom:50%;" />

<p>文字的外框用虚线表示，外框的左上角坐标就是(x, y)。  </p>
<h2 id="1-笛卡尔坐标系"><a href="#1-笛卡尔坐标系" class="headerlink" title="1. 笛卡尔坐标系"></a><font size=3>1. 笛卡尔坐标系</font></h2><p>在 LCD 的坐标系中，原点在屏幕的左上角。对于笛卡尔坐标系，原点在左下角。 freetype 使用笛卡尔坐标系，在显示时需要转换为 LCD 坐标系。  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/dadf112c33564ecfa089414f560799a8.png" alt="dadf112c33564ecfa089414f560799a8" style="zoom: 33%;" />

<p>X 方向坐标值是一样的。在 Y 方向坐标值需要换算，假设 LCD 的高度是 H。  在 LCD 坐标系中坐标是(x, y)，那么它在笛卡尔坐标系中的坐标值为(x, H-y)。  </p>
<p>反过来也是一样的，在笛卡尔坐标系中坐标是(x, y)，那么它在 LCD 坐标系中坐标值为(x, H-y)。 我们可以画到一起来看看： </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018070755124.png" alt="image-20241018070755124" style="zoom:50%;" />

<h2 id="2-每个字符大小不同？"><a href="#2-每个字符大小不同？" class="headerlink" title="2. 每个字符大小不同？"></a><font size=3>2. 每个字符大小不同？</font></h2><p>在使用 FT_Set_Pixel_Sizes 函数设置字体大小时，这只是“期望值”。比如“Fr”，如果把“ .”显示得跟其他汉字一样大，不好看。所以在显示一行文字时，后面文字其实是会受到前面文字的影响。</p>
<p>freetype 已经帮我们考虑到了这些影响。对于 freetype 字体的尺寸(freetype Metrics)，需要参考这个文档： <a target="_blank" rel="noopener" href="https://freetype.org/freetype2/docs/tutorial/step2.html">FreeType Tutorial &#x2F; II</a></p>
<p>上述文档中有两个关于字形布局的图：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018071235509.png" alt="image-20241018071235509" />

<p>在显示一行文字时，这些文字会基于同一个基线来绘制位图： baseline。在 baseline 上，每一个字符都有它的原点(origin)，比如上图中 baseline左边的黑色圆点就是字母“ g”的原点。当前 origin 加上 advance 就可以得到下一个字符的 origin，比如上图中 baseline 右边的黑色圆点。在显示一行中多个文件字时，后一个文字的原点依赖于前一个文字的原点及 advance。  </p>
<p>字符的位图是有可能越过 baseline 的，比如上图中字母“ g”在 baseline下方还有图像。上图中红色方框内就是字母“ g”所点据的位图，它的四个角落不一定与原点重合。</p>
<p>上图中那些 xMin 、 xMax 、 yMin 、 yMax 如何获得？可以使用FT_Glyph_Get_CBox 函数获得一个字体的这些参数，将会保存在一个 FT_BBox结构体中，以后想计算一行文字的外框时要用到 xMin 、 xMax 、 yMin 、 yMax这些信息：    </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span>  <span class="title">FT_BBox_</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    FT_Pos  xMin, yMin;</span><br><span class="line">    FT_Pos  xMax, yMax;</span><br><span class="line">&#125; FT_BBox;</span><br></pre></td></tr></table></figure>

<h2 id="3-显示一行字符"><a href="#3-显示一行字符" class="headerlink" title="3. 显示一行字符"></a><font size=3>3. 显示一行字符</font></h2><p>要显示一行文字时，每一个字符都有自己外框： xMin、 xMax、 yMin、 yMax。把这些字符的 xMin、 yMin 中的最小值取出来，把这些字符的 xMax、 yMax 中的最大值取出来，就可以确定这行文字的外框了。  </p>
<p>要想在指定位置(x, y)显示一行文字 ，步骤如下图：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018074744359.png" alt="image-20241018074744359" />

<p>第1步 先指定第 1 个字符的原点 pen 坐标为(0, 0)，计算出它的外框。</p>
<p>第2步 再计算右边字符的原点，也计算出它的外框，把所有字符都处理完后就可以得到一行文字的整体外框：假设外框左上角坐标为(x’, y’)。</p>
<p>第3步 想在(x, y)处显示这行文字，调整一下 pen 坐标即可。 怎么调整？pen 为(0, 0)时对应左上角(x’, y’)；那么左上角为(x, y)时就可以算出pen 为(x-x’, y-y’)。  </p>
<h2 id="4-freetype-的几个重要数据结构"><a href="#4-freetype-的几个重要数据结构" class="headerlink" title="4. freetype 的几个重要数据结构  "></a><font size=3>4. freetype 的几个重要数据结构  </font></h2><h3 id="4-1-FT-Library"><a href="#4-1-FT-Library" class="headerlink" title="4.1 FT_Library  "></a><font size=3>4.1 FT_Library  </font></h3><p>对应 freetype 库，使用 freetype 之前要先调用以下代码：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">FT_Library library; <span class="comment">/* 对应 freetype 库 */</span></span><br><span class="line">error = FT_Init_FreeType( &amp;library ); <span class="comment">/* 初始化 freetype 库 */</span></span><br></pre></td></tr></table></figure>

<p>在调用该函数之前，我们需要定义一个 FT_Library 类型变量， 调用 FT_Init_FreeType()函数时将该变量的指针作为参数传递进去。FT_Init_FreeType 完成以下操作 ：</p>
<p>（1）它创建了一个 FreeType 库对象，并将 library 作为库对象的句柄。</p>
<p>（2）FT_Init_FreeType()调用成功返回 0；失败将返回一个非零值错误码。  </p>
<h3 id="4-2-FT-Face"><a href="#4-2-FT-Face" class="headerlink" title="4.2 FT_Face  "></a><font size=3>4.2 FT_Face  </font></h3><p> FT_Face句柄它对应一个矢量字体文件，在源码中使用 FT_New_Face 函数打开字体文件后，就可以得到一个 face。  可以认为它对应一个字体文件：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">FT_Face face; <span class="comment">// face 对象的句柄</span></span><br><span class="line">error = FT_New_Face(library, font_file, <span class="number">0</span>, &amp;face ); <span class="comment">/* 加载字体文件 */</span></span><br></pre></td></tr></table></figure>

<p>应用程序通过调用 FT_New_Face()函数创建一个新的 face 对象， 其实就是加载字体文件。一个 face 对象描述了一个特定的字体样式和风格，如”Times New Roman Regular”和”Times New Roman Italic”对应两种不同的 face。</p>
<p>FT_New_Face()函数原型如下所示：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FT_Error <span class="title function_">FT_New_Face</span><span class="params">(FT_Library library, <span class="type">const</span> <span class="type">char</span> *filepathname, FT_Long face_index, FT_Face *aface)</span>;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>library： 一个 FreeType 库对象的句柄， face 对象从中建立；</p>
</li>
<li><p>filepathname： 字库文件路径名（一个标准的 C 字符串）；</p>
</li>
<li><p>face_index： 某些字体格式允许把几个字体 face 嵌入到同一个文件中，这个索引指示了你想加载的 face，其实就是一个下标，如果这个值太大，函数将会返回一个错误，通常把它设置为 0 即可！想要知道一个字体文件中包含了多少个 face，只要简单地加载它的第一个face（把 face_index 设置为 0），函数调用成功返回后， face&rarr;num_faces 的值就指示出了有多少个 face 嵌入在该字体文件中。</p>
</li>
<li><p>aface： 一个指向新建 face 对象的指针，当失败时其值被设置为 NULL。</p>
</li>
<li><p>返回值： 调用成功返回 0；失败将返回一个非零值的错误码。</p>
</li>
</ul>
<h3 id="4-3-FT-GlyphSlot"><a href="#4-3-FT-GlyphSlot" class="headerlink" title="4.3 FT_GlyphSlot  "></a><font size=3>4.3 FT_GlyphSlot  </font></h3><p>翻译一下，Glyph是字形，Slot是槽的意思。它其实就是用来保存字符的处理结果：比如转换后的 glyph、位图 ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018080116270.png" alt="image-20241018080116270" />

<p>一个 face 中有很多字符，生成一个字符的点阵位图时，位图保存在哪里？保存在字形槽中： face&rarr;glyph。生成第 1 个字符位图时，它保存在 face&rarr;glyph 中；生成第 2 个字符位图时，也会保存在 face&rarr;glyph 中，会覆盖第 1 个字符的位图。  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FT_GlyphSlot slot = face-&gt;glyph; <span class="comment">/* 字形槽: 字体的处理结果保存在这里 */</span></span><br></pre></td></tr></table></figure>

<h3 id="4-4-FT-Glyph"><a href="#4-4-FT-Glyph" class="headerlink" title="4.4 FT_Glyph  "></a><font size=3>4.4 FT_Glyph  </font></h3><p>字体文件中保存有字符的原始字形（关键点）信息，使用 freetype 的函数可以放大、缩小、旋转，这些新的关键点保存在字形槽中(注意：位图也是保存在字形槽中)。  </p>
<p>新的字形使用 FT_Glyph 来表示，可以使用这样的代码从 slot 中获得glyph：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">error = FT_Get_Glyph(slot , &amp;glyph);</span><br></pre></td></tr></table></figure>

<h3 id="4-5-FT-BBox"><a href="#4-5-FT-BBox" class="headerlink" title="4.5 FT_BBox  "></a><font size=3>4.5 FT_BBox  </font></h3><p>FT_BBox 结构体定义如下，它表示一个字符的外框，即新 glyph 的外框： </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span>  <span class="title">FT_BBox_</span></span></span><br><span class="line"><span class="class">&#123;</span></span><br><span class="line">    FT_Pos  xMin, yMin;</span><br><span class="line">    FT_Pos  xMax, yMax;</span><br><span class="line">&#125; FT_BBox;</span><br></pre></td></tr></table></figure>

<p>可以使用以下代码从 glyph 中获得这些信息：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &amp;bbox );</span><br></pre></td></tr></table></figure>

<h2 id="5-设置字体大小"><a href="#5-设置字体大小" class="headerlink" title="5. 设置字体大小"></a><font size=3>5. 设置字体大小</font></h2><p>设置字体的大小有两种方式： FT_Set_Char_Size()和 FT_Set_Pixel_Sizes()。  </p>
<h3 id="5-1-FT-Set-Pixel-Sizes-函数"><a href="#5-1-FT-Set-Pixel-Sizes-函数" class="headerlink" title="5.1 FT_Set_Pixel_Sizes()函数  "></a><font size=3>5.1 FT_Set_Pixel_Sizes()函数  </font></h3><p>调用 FT_Set_Pixel_Sizes()函数设置字体的宽度和高度，以像素为单位，使用示例如下所示：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FT_Set_Pixel_Sizes(face, <span class="number">50</span>, <span class="number">50</span>);</span><br></pre></td></tr></table></figure>

<p>第一个参数传入 face 句柄；第二个参数和第三个参数分别指示字体的宽度和高度，以像素为单位； 需要注意的是， 我们可以将宽度或高度中的任意一个参数设置为 0，那么意味着设置为 0 的参数将会与另一个参数保持相等，如下所示：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FT_Set_Pixel_Sizes(face, <span class="number">50</span>, <span class="number">0</span>);</span><br></pre></td></tr></table></figure>

<p>上面调用 FT_Set_Pixel_Sizes()函数时，将字体高度设置为 0， 也就意味着字体高度将自动等于字体宽度50。  </p>
<h3 id="5-2-FT-Set-Char-Size-函数"><a href="#5-2-FT-Set-Char-Size-函数" class="headerlink" title="5.2 FT_Set_Char_Size()函数  "></a><font size=3>5.2 FT_Set_Char_Size()函数  </font></h3><p>调用 FT_Set_Char_Size()函数设置字体大小， 示例如下所示，假设在一个 300x300dpi 的设备上把字体大小设置为 16pt：  </p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">error = FT_Set_Char_Size(</span><br><span class="line">                          face,  <span class="comment">// face 对象的句柄</span></span><br><span class="line">                          <span class="number">16</span>*<span class="number">64</span>, <span class="comment">// 以 1/64 点为单位的字体宽度</span></span><br><span class="line">                          <span class="number">16</span>*<span class="number">64</span>, <span class="comment">// 以 1/64 点为单位的字体高度</span></span><br><span class="line">                          <span class="number">300</span>,   <span class="comment">// 水平方向上每英寸的像素点数</span></span><br><span class="line">                          <span class="number">300</span>);  <span class="comment">// 垂直方向上每英寸的像素点数</span></span><br></pre></td></tr></table></figure>

<ul>
<li>字体的宽度和高度并不是以像素为单位，而是以 1&#x2F;64 点（point） 为单位表示（也就是 26.6 固定浮点格式） ，一个点是一个 1&#x2F;72英寸的距离。</li>
<li>同样也可将宽度或高度其中之一设置为 0， 那么意味着设置为 0 的参数将会与另一个参数保持相等。</li>
<li>dpi 参数设置为 0 时，表示使用默认值 72dpi。</li>
</ul>
<h2 id="6-实例代码框架"><a href="#6-实例代码框架" class="headerlink" title="6. 实例代码框架"></a><font size=3>6. 实例代码框架</font></h2><p>根据上面的描述，示例框架代码如下：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">char</span> **argv)</span></span><br><span class="line">&#123;</span><br><span class="line">	FT_Library	  library; <span class="comment">/* 对应freetype库 */</span></span><br><span class="line">	FT_Face 	  face;    <span class="comment">/* 对应字体文件 */</span></span><br><span class="line">	FT_GlyphSlot  slot;    <span class="comment">/* 对应字符的处理结果: 含glyph和位图 */</span></span><br><span class="line">	FT_Glyph      glyph;   <span class="comment">/* 对应字符经过处理后的glyph即外形、轮廓 */</span></span><br><span class="line">	FT_BBox       bbox;    <span class="comment">/* 字符的外框 */</span></span><br><span class="line">    FT_Vector     pen;     <span class="comment">/* 字符的原点 */</span></span><br><span class="line"></span><br><span class="line">	error = FT_Init_FreeType( &amp;library ); <span class="comment">/* 初始化freetype库 */</span></span><br><span class="line">	</span><br><span class="line">	error = FT_New_Face(library, font_file, <span class="number">0</span>, &amp;face ); <span class="comment">/* 加载字体文件 */</span></span><br><span class="line"></span><br><span class="line">	slot = face-&gt;glyph; <span class="comment">/* 插槽: 字体的处理结果保存在这里 */</span></span><br><span class="line"></span><br><span class="line">	FT_Set_Pixel_Sizes(face, <span class="number">24</span>, <span class="number">0</span>); <span class="comment">/* 设置大小 */</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">/* 确定坐标 */</span></span><br><span class="line">	pen.x = <span class="number">0</span>; <span class="comment">/* 单位: 1/64 像素 */</span></span><br><span class="line">	pen.y = <span class="number">0</span>; <span class="comment">/* 单位: 1/64 像素 */</span></span><br><span class="line"></span><br><span class="line">    FT_Set_Transform( face, <span class="number">0</span>, &amp;pen); <span class="comment">/* 变形 */</span></span><br><span class="line"></span><br><span class="line">	<span class="comment">/* 根据font_code加载字符, 得到新的glyph和位图, 结果保存在slot中 */</span></span><br><span class="line">    error = FT_Load_Char(face, font_code, FT_LOAD_RENDER); </span><br><span class="line"></span><br><span class="line">	error = FT_Get_Glyph(slot, &amp;glyph); <span class="comment">/* 从slot中得到新的glyph */</span></span><br><span class="line">		</span><br><span class="line">	FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &amp;bbox ); <span class="comment">/* 从glyph中得到字符外框 */</span></span><br><span class="line">		</span><br><span class="line">    draw_bitmap(&amp;slot-&gt;bitmap, lcd_x, lcd_y);  <span class="comment">/* 位图也保存在slot-&gt;bitmap中 */</span></span><br><span class="line"></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;	</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="7-完整实例"><a href="#7-完整实例" class="headerlink" title="7. 完整实例"></a><font size=3>7. 完整实例</font></h2><h3 id="7-1-实例1"><a href="#7-1-实例1" class="headerlink" title="7.1 实例1"></a><font size=3>7.1 实例1</font></h3><p>完整的实例代码和Makefile看这里：<a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-app-demo/tree/master/LV18_LCD_DEVICE/09_lcd_freetype_show_font_line">LV18_LCD_DEVICE&#x2F;09_lcd_freetype_show_font_line · 苏木&#x2F;imx6ull-app-demo - 码云 - 开源中国 (gitee.com)</a></p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018222432829.png" alt="image-20241018222432829" />

<p>将编译好的可执行程序和simsun.ttc 字体文件拷贝至开发板，这 2个文件放在同一个目录下，然后执行以下命令(其中的 3 个数字分别表示 LCD 的X 坐标、 Y 坐标、字体大小)： </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./app_demo ./data/simsun.ttc 100 200 90</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018222628602.png" alt="image-20241018222628602" />

<h3 id="7-2-实例2"><a href="#7-2-实例2" class="headerlink" title="7.2 实例2"></a><font size=3>7.2 实例2</font></h3><p>这里还有一个实例：</p>
<p><a target="_blank" rel="noopener" href="https://gitee.com/sumumm/imx6ull-app-demo/tree/master/LV18_LCD_DEVICE/10_lcd_freetype_show_font_line_angle">LV18_LCD_DEVICE&#x2F;10_lcd_freetype_show_font_line_angle · 苏木&#x2F;imx6ull-app-demo - 码云 - 开源中国 (gitee.com)</a></p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018233207290.png" alt="image-20241018233207290" />

<p>我们编译完毕后执行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">./app_demo ./data/simsun.ttc 10 24</span><br></pre></td></tr></table></figure>

<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/LV18-01-LCD%E5%BA%94%E7%94%A8%E7%BC%96%E7%A8%8B-08-FreeType%E5%BA%93%E7%9A%84%E5%BA%94%E7%94%A8/img/image-20241018233242368.png" alt="image-20241018233242368" />

<p>就会看到屏幕上有斜体的文字显示出来。</p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/449e2fe8.html">LV18-01-LCD应用编程-08-FreeType库的应用</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2024年10月27日 - 19:29</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/449e2fe8.html" title="LV18-01-LCD应用编程-08-FreeType库的应用">https://sumumm.github.io/post/449e2fe8.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/ALPHA-LV03-%E5%BA%94%E7%94%A8%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> (ALPHA)LV03-应用开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/38c950cd.html" rel="prev" title="LV18-01-LCD应用编程-09-横竖屏切换">
                  <i class="fa fa-angle-left"></i> LV18-01-LCD应用编程-09-横竖屏切换
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/17007ac4.html" rel="next" title="LV18-01-LCD应用编程-07-字符的编码">
                  LV18-01-LCD应用编程-07-字符的编码 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
